package net.hn.hnms.biz.mine.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.hn.hnms.biz.mine.domain.HomeLinkConfig;
import net.hn.hnms.biz.mine.service.IHomeLinkConfigService;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@RestController
@RequestMapping("config/link")
@Api(value = "首页链接配置控制器", tags = {"首页链接配置"})
public class HomeLinkConfigController extends BaseController {

    @Resource
    private IHomeLinkConfigService mineConfigService;

    /**
     * 新增进
     */
    @ApiOperation("新增")
    @SaCheckPermission("config:link:add")
    @PostMapping("/add")
    public R<Void> add(@Validated @RequestBody HomeLinkConfig homeLinkConfig) {
        return toAjax(mineConfigService.insert(homeLinkConfig));
    }

    /**
     * 删除
     */
    @ApiOperation("删除")
    @SaCheckPermission("config:link:delete")
    @ApiImplicitParam(name = "idList", value = "要删除的id值,用逗号间隔", required = true, allowMultiple = true, dataType = "String", paramType = "query")
    @DeleteMapping("delete")
    public R<Void> delete(@RequestParam("idList") List<String> idList) {
        mineConfigService.deleteBatch(idList);
        return R.ok();
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @SaCheckPermission("config:link:update")
    @PutMapping("/update")
    public R<Void> update(@Validated @RequestBody HomeLinkConfig homeLinkConfig) {
        mineConfigService.updateById(homeLinkConfig);
        return R.ok();
    }

    /**
     * 获取
     */
    @ApiOperation("获取分页列表")
    @GetMapping("/page")
    @AutoSetMineCode
    public R<ResponsePage<HomeLinkConfig>> page(HomeLinkConfig homeLinkConfig, PageQuery pageQuery) {
        return R.ok(mineConfigService.selectPageList(homeLinkConfig, pageQuery));
    }

    /**
     * 获取列表
     */
    @ApiOperation("获取列表")
    @GetMapping("/list")
    @AutoSetMineCode
    public R<List<HomeLinkConfig>> list(HomeLinkConfig homeLinkConfig) {
        return R.ok(mineConfigService.selectList(homeLinkConfig));
    }


}
